import 'package:dio/dio.dart';
import '../../utils/logger.dart';

class LoggerInterceptor extends Interceptor {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    final method = options.method.toUpperCase();
    final url = options.uri.toString();
    
    NetworkLogInterceptor.logRequest(
      method,
      url,
      headers: options.headers,
      data: options.data,
    );
    
    super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    final method = response.requestOptions.method.toUpperCase();
    final url = response.requestOptions.uri.toString();
    final statusCode = response.statusCode;
    final responseData = response.data;
    
    NetworkLogInterceptor.logResponse(
      method,
      url,
      statusCode: statusCode,
      response: responseData,
    );
    
    super.onResponse(response, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {
    final method = err.requestOptions.method.toUpperCase();
    final url = err.requestOptions.uri.toString();
    
    NetworkLogInterceptor.logError(
      method,
      url,
      error: err.error,
      stackTrace: err.stackTrace,
    );
    
    super.onError(err, handler);
  }
}